﻿using Microsoft.AspNetCore.Mvc;
using PowerHub.MES.Common.Utility;
using PowerHub.MES.DTO.Production.DTO;
using PowerHub.MES.DTO.Production.QueryDTO;
using PowerHub.MES.Entities.Production;
using PowerHub.MES.IServices.IProduction;
using PowerHub.MES.ReturnEntity;

namespace PowerHub.MES.Controllers.Production
{

    /// <summary>
    ///生产工单
    /// </summary>
    [ApiController]
    [Route("Api/MES/Production/[controller]/[action]")]
    public class WorkOrderController
    {

        private IProduction_WorkOrderServices _Production_WorkOrderServices;

        public WorkOrderController(IProduction_WorkOrderServices WorkOrderServices)
        {
            _Production_WorkOrderServices = WorkOrderServices;
        }

        /// <summary>
        /// 获取生产工单列表
        /// </summary>
        /// <returns></returns>
        /// <exception cref="Exception"></exception>
        [HttpPost]
        [FunctionDescription("获取生产工单列表")]
        public async Task<OperationPageResult<List<Production_WorkOrder>>> GetProduction_WorkOrderPageListAsync([FromBody] QueryProduction_WorkOrderDTO pageQuery)
        {
            return await _Production_WorkOrderServices.GetProduction_WorkOrderPageListAsync(pageQuery);
        }

        /// <summary>
        /// 根据生产工单id获取工单信息
        /// </summary>
        /// <returns></returns>
        /// <exception cref="Exception"></exception>
        [HttpPost]
        [FunctionDescription("根据生产工单id获取工单信息")]
        public async Task<OperationResult<Production_WorkOrder>> GetProduction_WorkOrderByIdAsync([FromBody] QueryProduction_WorkOrderDTO pageQuery)
        {
            return await _Production_WorkOrderServices.GetProduction_WorkOrderByIdAsync(pageQuery);
        }
        
        /// <summary>
        /// 根据生产工单id获取分解生产任务
        /// </summary>
        /// <returns></returns>
        /// <exception cref="Exception"></exception>
        [HttpPost]
        [FunctionDescription("根据生产工单id获取分解生产任务")]
        public async Task<OperationResult<Production_WorkOrderProductionTaskDTO>> GetProduction_WorkOrderByIdTaskListAsync([FromBody] QueryProduction_WorkOrderDTO pageQuery)
        {
            return await _Production_WorkOrderServices.GetProduction_WorkOrderByIdTaskListAsync(pageQuery);
        }


        /// <summary>
        /// 批量删除生产工单
        /// </summary>
        /// <returns></returns>
        /// <exception cref="Exception"></exception>
        [HttpPost]
        [FunctionDescription("批量删除生产工单")]
        public async Task<OperationResult<bool>> DeletionProduction_WorkOrderAsync([FromBody] List<string> Query)
        {
            return await _Production_WorkOrderServices.DeletionProduction_WorkOrderAsync(Query);
        }

        /// <summary>
        /// 更新生产工单
        /// </summary>
        /// <returns></returns>
        /// <exception cref="Exception"></exception>
        [HttpPost]
        [FunctionDescription("更新生产工单")]
        public async Task<OperationResult<bool>> UpdateProduction_WorkOrderAsync([FromBody] Production_WorkOrderDTO Query)
        {
            return await _Production_WorkOrderServices.UpdateProduction_WorkOrderAsync(Query);
        }

        /// <summary>
        /// 添加生产工单
        /// </summary>
        /// <returns></returns>
        /// <exception cref="Exception"></exception>
        [HttpPost]
        [FunctionDescription("添加生产工单")]
        public async Task<OperationResult<bool>> CreateProduction_WorkOrderAsync([FromBody] Production_WorkOrderDTO Query)
        {
            return await _Production_WorkOrderServices.CreateProduction_WorkOrderAsync(Query);
        }
    }
}
